package com.sugon.cloudalibabapayment.controller;

import com.alibaba.nacos.shaded.io.grpc.internal.JsonUtil;
import com.sugon.cloudalibabapayment.entity.User;
import com.sugon.cloudgateway.jwt.JwtUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.web.bind.annotation.*;
//import com.alibaba.fastjson;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * payment 控制层
 *
 * @author JH
 * @version 1.0
 * @since 2023/2/20 11:22
 */
@RestController
public class PaymentController {

    // @Value(“${}”)是用来获取配置文件
    // @Value("${server.port}") 获取application.yml文件中port
    @Value("${server.port}")
    private String serverPort;

    @GetMapping(value = "/payment/nacos/{id}")
    public String getPayment(@PathVariable("id") Integer id) {
        return "nacos registry, serverPort: " + serverPort + "\t id: " + id;
    }

    @GetMapping(value = "/payment/get/{id}")
    public String gwPayment(@PathVariable("id") Long id) {
        return "gateway test, actual ServerPort: " + serverPort + "\t id: " + id;
    }

    @GetMapping(value = "/payment/lb")
    public String lbPayment() {
        return "nacos registry, serverPort: " + serverPort;
    }

//    @PostMapping("/login")
//    public String login(@RequestBody User user){
//        //在redis中根据用户名查找密码
//        String password = redisTemplate.opsForValue().get(user.getUsername());
//        System.out.println(password);
//        //BCrypt.checkpw 密码的校验
//        boolean checkResult = BCrypt.checkpw(user.getPassword(), password);
//        if (checkResult){
//            Map<String, String> info = new HashMap<>();
//            info.put("username", user.getUsername());
//            String token = JwtUtil.createJWT(UUID.randomUUID().toString(), user.getUsername(), 3600L*1000);
//            info.put("token",token);
//            return JSONUtil.toJsonStr(info);
//
//        }else {
//            return "登录失败";
//        }
//    }


}
